package lanqiao.hol.control;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.TBStudentBean;
import org.lanqiao.tjut.model.ModelFactory;
import org.lanqiao.tjut.myUtils.MyUtils;

import com.alibaba.fastjson.JSON;

/**
 * Ajax的删除操作 StudentInfoAjaxDeleteServlet
 */
@WebServlet("/StudentInfoAjaxDeleteServlet")
public class StudentInfoAjaxDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String delIndex = request .getParameter("delIndex");
	//如果删除记录不为null，则进行删除操作
	if(delIndex !=null && !delIndex.equals("")){
		//进行删除操作
		//调用module层进行删除操作
		ModelFactory.getStudentModelInstance().deleteStudentIdInfoById(delIndex);
	}
	//无论删除成功与否，都要再进行ajax查询操作
	// 获取查询表单的实体类参数
			TBStudentBean stuB = MyUtils.convertRequest2Bean(request, TBStudentBean.class, null, null);
			// 调用model层进行数据查询
			List<TBStudentBean> lstStus = ModelFactory.getStudentModelInstance().queryStudentInfoByParas(stuB);
			//发回相应内容之前，需要将返回的java的数据结果对象转换为json对象
			//将查询结果集转换为json对象
			String json = JSON.toJSONStringWithDateFormat(lstStus, "yyyy-MM-dd HH:mm:ss");
			// 使用writer对象将服务器响应内容写到客户端
			PrintWriter pw = response.getWriter();
			pw.write(json);
			pw.flush();
			pw.close();

	}

}
